﻿using System.Data.Entity.ModelConfiguration;

namespace Delphi.Mimir.Data.Entities.Final.Mappings {
    public class ManagedProductMap : EntityTypeConfiguration<ManagedProduct> {
        public ManagedProductMap() {
            /******************************************************************
            /* Table
            /*****************************************************************/
            ToTable("fin.pfm_managed_products");

            /******************************************************************
            /* Primary Key
            /*****************************************************************/
            HasKey(a => a.ManagedProductId);

            /******************************************************************
            /* Index
            /*****************************************************************/
            // None

            /******************************************************************
            /* Relationships
            /*****************************************************************/
            // tbd
            HasRequired<Symbol>(a => a.Symbol)
                .WithOptional()
                .WillCascadeOnDelete(true);

            HasMany<ManagedProductPosition>(a => a.ManagedProductPositions)
                .WithRequired(a => a.ManagedProduct)
                .HasForeignKey(a => a.ManagedProductId);

            HasMany<Order>(a => a.Orders)
                .WithRequired(a => a.ManagedProduct)
                .HasForeignKey(a => a.ManagedProductId);

            HasMany<AssetUniverse>(a => a.AssetUniverses)
                .WithRequired(a => a.ManagedProduct)
                .HasForeignKey(a => a.ManagedProductId);

            HasMany<CashTransaction>(a => a.CashTransactions)
                .WithRequired(a => a.ManagedProduct)
                .HasForeignKey(a => a.ManagedProductId);

            /******************************************************************
            /* Properties
            /*****************************************************************/
            Property(a => a.ManagedProductId)
                .IsRequired()
                .HasColumnName("mpd_id");

            Property(a => a.SymbolId)
                .IsRequired()
                .HasColumnName("mpd_sym_id");

            Property(a => a.IsActiveManaged)
                .IsOptional()
                .HasColumnName("mpd_managed_fg");

            Property(a => a.ValidFromDate)
                .IsRequired()
                .HasColumnName("mpd_valid_frm_dt");

            Property(a => a.ValidUntilDate)
                .IsRequired()
                .HasColumnName("mpd_valid_til_dt");

            
        }
    }
}
